home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13894 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: tank.news.pipex.net!pipex!iol!usenet
  2. From: David Byrden <Goyra@iol.ie>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help: Can't extract fractional digits of DOUBLE
  5. Date: 27 Mar 1996 20:52:55 GMT
  6. Organization: Ireland On-Line
  7. Message-ID: <4jc9r7$hnf@nuacht.iol.ie>
  8. References: <4jc3cc$5nj@atlas.tncnet.com>
  9. NNTP-Posting-Host: dialup-079.dublin.iol.ie
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22KIT (Windows; I; 16bit)
  14.  
  15. Simon Lee (Simon Lee) wrote:
  16. >
  17. >Hello everyone,
  18. >
  19. >I'm trying to take a double value and extract each digit from the value.
  20.  
  21.  
  22.    Not so easy, I'm afraid. The numbers are stored, not in decimal, but in 
  23. a pattern based on binary, so multiplying them by 10 completely changes 
  24. their bit pattern and potentially introduces more nonzero bits at the 
  25. least significant positions. 
  26.  
  27.    If you think of the number as being in base 2, and multiply by TWO each 
  28. time, extracting binary digits, you will eventually get all the fractional 
  29. bits out. You could then convert to decimal as a second step. Fractional 
  30. nonrepeating binary numbers do turn into fractional nonrepeating decimal 
  31. numbers.
  32.  
  33.  
  34.                                           David
  35.  
  36.  
  37.  
  38.